package com.example.idea.service;

import com.example.idea.entity.Logs;
import com.example.idea.mapper.LogsMapper;
import com.example.idea.utils.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogsService {

    @Resource
    private LogsMapper logsMapper;

    public void add(Logs logs) {
        logsMapper.add(logs);
    }

    public void update(Logs logs) {
        logsMapper.update(logs);
    }

    public void delete(Integer id) {
        logsMapper.delete(id);
    }

    public Logs query(Integer id) {
        return logsMapper.query(id);
    }

    public void deleteBatch(List<Integer> ids) {
        String idsStr = ids.toString().replace("[", "").replace("]", "");
        logsMapper.deleteBatch(idsStr);
    }

    public List<Logs> list() {
        return logsMapper.list();
    }

    public List<Logs> selectList(Logs logs) {
        return logsMapper.selectList(logs);
    }

    public Page<Logs> selectByPage(Integer pageNum, Integer pageSize, String operation, String type) {
        Integer skipNum = (pageNum - 1) * pageSize;
        Page<Logs> page = new Page<>();
        List<Logs> logsList = logsMapper.selectByPage(skipNum, pageSize, operation, type);
        Integer total = logsMapper.selectCountByPage(operation, type);
        page.setList(logsList);
        page.setTotal(total);
        return page;
    }
}
